using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using SolanumSolstice_Windows.Units;
using SolanumSolstice_Windows.Mapping;

namespace SolanumSolstice_Windows.Buildings
{
    public class Base : Building
    {
        protected int wood;
        protected int food;
        protected int maxFood;
        protected int maxWood;

        #region Accessors
        public int Wood
        {
            get
            {
                return wood;
            }
            set
            {
                wood = value;
            }
        }

        public int Food
        {
            get
            {
                return food;
            }
            set
            {
                food = value;
            }
        }
        #endregion

        public Base(ContentManager content, string name, Vector2 position, Vector2 entrance, int zombieCount)
            : base(content, name, position, entrance, zombieCount)
        {
            wood = 20;
            food = 20;
            maxWood = 120;
            maxFood = 120;

            //this needs to change: no picture available right now
            texture = content.Load<Texture2D>("Content\\Txtr\\Bldg\\building_base");
            width = texture.Width;
            height = texture.Height;

            buildingType = BuildingType.Base;
        }

        public void DepositWood(int amount, Civilian depositor)
        {
            wood += amount;

            if (wood > maxWood)
            {
                wood = maxWood;
            }

            depositor.WoodHolding = 0;
            depositor.SetGatherTarget(depositor.TargetGatherBuilding.Entrance, depositor.TargetGatherBuilding);
        }

        public void DepositFood(int amount, Civilian depositor)
        {
            food += amount;

            if (food > maxFood)
            {
                food = maxFood;
            }

            depositor.FoodHolding = 0;

            depositor.SetGatherTarget(depositor.TargetGatherBuilding.Entrance, depositor.TargetGatherBuilding);
        }

        public void UseWood(int amount)
        {
            wood -= amount;

            if (wood < 0)
            {
                wood = 0;
            }
        }

        public void UseFood(int amount)
        {
            food -= amount;

            if (food < 0)
            {
                food = 0;
            }
        }

        public override void DrawHUD(Microsoft.Xna.Framework.Graphics.SpriteBatch spritebatch, Microsoft.Xna.Framework.Rectangle drawBoundary)
        {
            spritebatch.DrawString(hudFont, "Wood: " + wood, new Vector2(drawBoundary.X, drawBoundary.Y), Color.White);
            spritebatch.DrawString(hudFont, "Food: " + food, new Vector2(drawBoundary.X, drawBoundary.Y + 20), Color.White);
        }
    }
}
